package dao;
import java.util.List;

import model.Admin;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

import dao.support.sql.SqlObject;
import support.GridResult;
import support.Result;

import java.util.Map;

import net.sf.json.JSONArray;
import support.GridResult;
import dao.support.cache.Cache;
import model.customer.*;
import model.data.DataDictionary;
@Component
public class CustomerDao extends BaseDao {
	public String customer_query(SqlObject so)
	{
		Object obj = this.querySQLRead(so.getSqlCount()).get(0).get("c");
		int total = Integer.parseInt(obj.toString());
		return new GridResult(so.getPage(), (total-1)/so.getRows()+1, total, this.querySQLRead(so.getSqlRows())).toString();
	}
	public CustomerInfor customer_findbyid(String customer_id)
	{
		int id = Integer.parseInt(customer_id);
		return (CustomerInfor) super.loadById(id, CustomerInfor.class);

	}
	public void customer_update(CustomerInfor customer)
	{
	    this.update(customer);
	}
	
	public void contacts_update(Contacts contacts)
	{
	    this.update(contacts);
	}
	public void contacts_delete(String contacts_id)
	{
		Object []list = JSONArray.fromObject(contacts_id).toArray();
		for(Object obj : list)
		{
			String s = obj.toString();
			this.delete(Integer.parseInt(s), Contacts.class);
		}
	}
	public Contacts contacts_findbyid(String contacts_id)
	{
		int id = Integer.parseInt(contacts_id);
		return (Contacts) super.loadById(id, Contacts.class);
	}
	public HistoryOrder historyorder_findbyid(String historyorder_id)
	{
		int id= Integer.parseInt(historyorder_id);
		return (HistoryOrder) super.loadById(id, HistoryOrder.class);
	}
	public void contacts_add(Contacts contacts)
	{
		this.create(contacts);
	}
	public CustomerInfor getById(int id)
	{
		return (CustomerInfor) this.loadById(id, CustomerInfor.class);
	}
}
